export default function registerDownload(lf) {
    lf.register('ifelse', ({ PolygonNode, PolygonNodeModel, h }) => {
        class Node extends PolygonNode {
            getIconShape() {
                return h(
                    'svg', {
                        x: 34,
                        y: 6,
                        width: 15,
                        height: 15,
                        viewBox: "0 0 1274 1024",
                    },
                    h(
                        'path', {
                            fill: 'red',
                            d: 'M817.152 202.752 817.152 202.752C737.28 122.88 628.736 75.776 509.952 75.776c-118.784 0-229.376 49.152-307.2 126.976l0 0c-77.824 77.824-126.976 186.368-126.976 307.2 0 118.784 49.152 229.376 126.976 307.2 77.824 79.872 188.416 126.976 307.2 126.976 120.832 0 229.376-49.152 307.2-126.976 79.872-77.824 126.976-186.368 126.976-307.2C946.176 389.12 897.024 280.576 817.152 202.752zM770.048 770.048c-65.536 65.536-157.696 108.544-260.096 108.544-102.4 0-194.56-40.96-260.096-108.544C184.32 704.512 141.312 612.352 141.312 509.952s40.96-194.56 108.544-260.096C317.44 184.32 409.6 141.312 509.952 141.312c100.352 0 192.512 40.96 258.048 106.496l2.048 2.048c65.536 65.536 108.544 157.696 108.544 260.096S837.632 704.512 770.048 770.048z'
                        }
                    )
                )
            }
            getShape() {
                const { model } = this.props
                const { width, height, x, y, points } = model
                const {
                    fill,
                    fillOpacity,
                    strokeWidth,
                    stroke,
                    strokeOpacity,
                } = model.getNodeStyle()
                const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
                const pointsPath = points.map(point => point.join(',')).join(' ')
                const style = model.getNodeStyle()
                if (style.debug) {
                    return h(
                        'g', {
                            transform
                        }, [
                            h(
                                'polygon', {
                                    points: pointsPath,
                                    fill,
                                    stroke,
                                    strokeWidth,
                                    strokeOpacity,
                                    fillOpacity
                                }
                            ),

                            this.getIconShape()
                        ]
                    )
                } else {
                    return h(
                        'g', {
                            transform
                        }, [
                            h(
                                'polygon', {
                                    points: pointsPath,
                                    fill,
                                    stroke,
                                    strokeWidth,
                                    strokeOpacity,
                                    fillOpacity
                                }
                            ),
                        ]
                    )
                }

            }
        }
        class Model extends PolygonNodeModel {
            constructor(data, graphModel) {
                data.text = {
                    value: (data.text && data.text.value) || 'ifelse',
                    x: data.x,
                    y: data.y
                }
                super(data, graphModel)
                const lenght = 40
                    // this.points = [
                    //     [lenght, 10],
                    //     [lenght * 2, lenght],
                    //     [lenght, lenght * 2 - 10],
                    //     [0, lenght]
                    // ]
                this.points = [
                    [lenght, 0],
                    [lenght * 2, lenght],
                    [lenght, lenght * 2],
                    [0, lenght]
                ]
            }

            // 审批过后变绿
            setAttributes() {

            }

            getNodeStyle() {
                const style = super.getNodeStyle()
                const { properties: { isStayed, deBug, isPassed } } = this;
                // 断点黄色
                if (isStayed) {
                    style.strokeWidth = '2'
                    style.stroke = '#DAA520'
                }
                // 走过绿色
                if (isPassed) {
                    style.strokeWidth = '2'
                    style.stroke = 'green'
                }
                // 打断点出现的样式
                if (deBug) {
                    style.debug = true
                }
                return style
            }
        }
        return {
            view: Node,
            model: Model
        }
    })
}